What is @prismicio/client?
@prismicio/client is an official JavaScript client library for Prismic, a headless CMS. It allows developers to easily query and fetch content from Prismic repositories, manage content models, and handle previews. The package is designed to work seamlessly with modern JavaScript frameworks and libraries.
What are @prismicio/client's main functionalities?
Initialize the Client
This feature allows you to initialize the Prismic client with your repository name and access token. This is the first step to interact with your Prismic content.
const prismic = require('@prismicio/client');
const client = prismic.createClient('your-repo-name', { accessToken: 'your-access-token' });
Fetch All Documents
This feature allows you to fetch all documents from your Prismic repository. It returns an array of documents that you can then manipulate or display in your application.
const documents = await client.getAll();
console.log(documents);
Query by Type
This feature allows you to query documents by their type. For example, you can fetch all documents of type 'blog_post'.
const blogPosts = await client.getByType('blog_post');
console.log(blogPosts);
Fetch a Single Document by ID
This feature allows you to fetch a single document by its ID. This is useful when you need to retrieve specific content based on its unique identifier.
const document = await client.getByID('document-id');
console.log(document);
Handle Previews
This feature allows you to handle content previews. It resolves the preview token and document ID to fetch the preview content, which is useful for previewing unpublished changes.
const previewData = await client.getPreviewResolver(token, documentId).resolve(linkResolver, '/');
console.log(previewData);
Other packages similar to @prismicio/client
contentful
Contentful is another headless CMS that provides a JavaScript client library for fetching and managing content. It offers similar functionalities to @prismicio/client, such as querying content, handling previews, and managing content models. However, Contentful has a different API structure and may offer more advanced features for enterprise use.
strapi
Strapi is an open-source headless CMS that allows you to create and manage content APIs. It provides a JavaScript client library for interacting with its API. Strapi is highly customizable and can be self-hosted, offering more control over the CMS environment compared to Prismic.
@prismicio/client
The official JavaScript + TypeScript client library for Prismic.
- Query content from a Prismic repository.
- Refines queries using Filters.
- Automatically query draft content during preview sessions.
- Built for browser and server usage.
import * as prismic from "@prismicio/client"
const client = prismic.createClient("my-repository")
const blogPosts = await client.getAllByType("blog_post")
Install
npm install @prismicio/client
Documentation
To discover what's new on this package check out the changelog. For full documentation, visit the official Prismic documentation.
Contributing
Whether you're helping us fix bugs, improve the docs, or spread the word, we'd love to have you as part of the Prismic developer community!
Asking a question: Open a new topic on our community forum explaining what you want to achieve / your question. Our support team will get back to you shortly.
Reporting a bug: Open an issue explaining your application's setup and the bug you're encountering.
Suggesting an improvement: Open an issue explaining your improvement or feature so we can discuss and learn more.
Submitting code changes: For small fixes, feel free to open a pull request with a description of your changes. For large changes, please first open an issue so we can discuss if and how the changes should be implemented.
For more clarity on this project, check out the detailed CONTRIBUTING.md document.
License
Copyright 2013-2024 Prismic <contact@prismic.io> (https://prismic.io)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.